
import React from 'react'
// 引入store
import store from '../../store/store'
// 引入的分别是累加的action,累减的action,异步函数处理的action
import { incrementAction,decrementAction,waitIncrementAction } from "../../store/actions/countAction";

export default function Count() {
    // getState获取count的值
    const {count} = store.getState().count
    const {movieList}=store.getState().movie
    const increamentHandle=()=>{
        // 调用actions里面封装好的函数
        store.dispatch(incrementAction(1))
    }
    const decreamentHandle=()=>{
        // 调用actions里面封装好的函数
        store.dispatch(decrementAction(1))
    }
    const ifevenIncreamentHandle=()=>{
        if(count%2===0){
            // 调用actions里面封装好的函数
            store.dispatch(incrementAction(1))
        }
    }
    const waitIncreamentHandle=()=>{
        // 调用actions里面封装好的函数
        store.dispatch(waitIncrementAction(1))
    }
  return (
    <div>
        <h1>我是count组件,我的值是{count}</h1>
        <h2>movie请求的电影数据是{movieList.length}个</h2>
        <button onClick={increamentHandle}>累加</button>
        <button onClick={decreamentHandle}>累减</button>
        <button onClick={ifevenIncreamentHandle}>遇到偶数就加1</button>
        <button onClick={waitIncreamentHandle}>等两秒在减1</button>
    </div>
  )
}
